/**
 * Copyright (c) 2009-2011, chunquedong(YangJiandong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 
 * History:
 *     2010-05-05  Jed Young  Creation
 */
package chunmap.example.buffer;

import java.util.List;

import chunmap.example.BaseGeometryMap;
import chunmap.model.geom.Geometry;
import chunmap.model.geom.GeometryException;
import chunmap.model.geom.LineString;
import chunmap.model.geom.Polygon;
import chunmap.model.geom.WktReader;
import chunmap.model.operate.buffer.LineBuffer;
import chunmap.model.operate.buffer.PointBuffer;
import chunmap.model.operate.overlay.OverLayOp;
import chunmap.util.math.MyDouble;

/**
 * @author chunquedong
 * 
 */
public class LineStringBufferTest extends BaseGeometryMap {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		LineStringBufferTest me = new LineStringBufferTest();
		me.init();
	}

	@Override
	protected void addGeometry(List<Geometry> geoms) {

		WktReader wkt = new WktReader();
		// Geometry g = wkt
		// .read("LINESTRING(1.0 6.0,5.999998414659173 1.0039816335536662,1.0079632645824341 -3.999993658637697,-3.9999857319385903 0.9880551094385923,1.0 6.0)");
		// LineString ls = (LineString) g;
		Geometry g2 = wkt
				.read("LINESTRING(-2.639991350383829 -1.7999950537374092,-1.8399918576928131 -1.7999950537374092,-1.8399918576928131 -0.9999955610463935,-2.639991350383829 -0.9999955610463935,-2.639991350383829 -1.7999950537374092)");
		LineString ls2 = (LineString) g2;

		Geometry g3 = wkt
				.read("LINESTRING(-2.639991350383829 -1.7999950537374092,-1.8399918576928131 -1.7999950537374092,-1.8399918576928131 -0.9999955610463935,-2.639991350383829 -0.9999955610463935)");

		Geometry g4 = wkt
				.read("LINESTRING(-2.639991350383829 -0.9999955610463935,-2.639991350383829 -1.7999950537374092)");
		LineString ls4 = (LineString) g4;

		if (!g3.isValid())
			throw new GeometryException();
		if (!g4.isValid())
			throw new GeometryException();

		LineBuffer lb = new LineBuffer();
		OverLayOp op = new OverLayOp();

		// Polygon pg2 = lb.lineStringBuffer((LineString) g2, 0.1);
		Polygon pg3 = lb.lineStringBuffer((LineString) g3, 0.1);
		Polygon pg4 = lb.lineStringBuffer((LineString) g4, 0.1);

		// PointBuffer pb = new PointBuffer();
		// Polygon pg3 = pb.createBuffer(l2.firstPoint(), 0.1);

		// Polygon pgr = op.computeUnion(pg3, pg4).getGeometry(0);

		// geoms.add(pgr);
		geoms.add(pg3);
		geoms.add(pg4);
		// geoms.add(pg3.getBoundary());
		// geoms.add(pg4.getBoundary());
		// geoms.add(ls);
		// geoms.add(ls2);
	}
}